package com.education.platform.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * 消息表
 *
 * @author education-platform
 * @since 2024-10-07
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("message")
@JsonIgnoreProperties(value = {"handler"})
public class Message {

    /**
     * 主键ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 发送者ID，NULL表示系统消息
     */
    @TableField("from_user_id")
    private Long fromUserId;

    /**
     * 接收者ID
     */
    @TableField("to_user_id")
    private Long toUserId;

    /**
     * 会话ID
     */
    @TableField("conversation_id")
    private String conversationId;

    /**
     * 消息类型
     */
    @TableField("type")
    private String type;

    /**
     * 内容类型
     */
    @TableField("content_type")
    private String contentType;

    /**
     * 消息标题
     */
    @TableField("title")
    private String title;

    /**
     * 消息内容
     */
    @TableField("content")
    private String content;

    /**
     * 扩展数据
     */
    @TableField("extra_data")
    private String extraData;

    /**
     * 消息状态
     */
    @TableField("status")
    private String status;

    /**
     * 已读时间
     */
    @TableField("read_at")
    private LocalDateTime readAt;

    /**
     * 创建时间
     */
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    private LocalDateTime createdAt;

    // 关联对象（用于XML映射）
    @TableField(exist = false)
    private User fromUser;

    @TableField(exist = false)
    private User toUser;

    // 枚举定义
    public enum Type {
        SYSTEM("系统消息"),
        CHAT("聊天消息"),
        NOTIFICATION("通知消息"),
        BROADCAST("广播消息");

        private final String description;

        Type(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }

    public enum ContentType {
        TEXT("文本"),
        IMAGE("图片"),
        FILE("文件"),
        VOICE("语音"),
        VIDEO("视频");

        private final String description;

        ContentType(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }

    public enum Status {
        UNREAD("未读"),
        READ("已读"),
        DELETED("已删除");

        private final String description;

        Status(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }
}
